package demo1;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String[] strings = new String[n];
        int[] array = new int[n];
        System.out.println();

        for (int i = 0; i < n; i++) {
            strings[i] = scanner.nextLine();
        }

        for (int i = 0; i < n; i++) {
            if(strings[i].equals("Bank")){
                array[i] = 0;
            } else if(strings[i].equals("withdraw")){
                array[i] = 1;
            }else if(strings[i].equals("transfer")){
                array[i] = 2;
            }else if(strings[i].equals("deposit")){
                array[i] = 3;
            }
        }
        long[] balance = new long[n];
        Bank bank = new Bank(balance);

        for (int i = 0; i < n; i++) {
            switch (array[i]){
                case 0:{
                    System.out.println("请输入银行账户初始存款");
                    for (int j = 0; j < n; j++) {
                        System.out.println("第" + ( j + 1 ) + "个账户存款为:");
                        balance[j] = (long) scanner.nextInt();
                    }
                    bank = new Bank(balance);
                }break;
                case 1:{
                    System.out.println("请输入取款账号");
                    int account = scanner.nextInt();
                    System.out.println("请输入取款金额");
                    long money = scanner.nextInt();
                    if (!bank.withdraw(account,money)) {
                        System.out.println("取款金额大于存款，取款失败");
                    }else {
                        System.out.println("取款成功");
                        bank.show(account);
                    }
                }break;
                case 2:{
                    System.out.println("请输入转出账号");
                    int account1 = scanner.nextInt();
                    System.out.println("请输入转入账号");
                    int account2 = scanner.nextInt();
                    System.out.println("请输入转入金额");
                    long money = scanner.nextLong();
                    if (!bank.transfer(account1,account2,money)) {
                        System.out.println("转出金额大于存款，交易失败");
                    }else {
                        System.out.println("交易成功");
                        System.out.print("账户" + account1);
                        bank.show(account1);
                        System.out.print("账户" + account2);
                        bank.show(account2);
                    }
                }break;
                case 3:{
                    System.out.println("请输入存款账号");
                    int account = scanner.nextInt();
                    System.out.println("请输入存款金额");
                    long money = scanner.nextLong();
                    if (!bank.deposit(account,money)) {
                        System.out.println("账号错误，存款失败");
                    }else {
                        System.out.println("存款成功");
                        bank.show(account);
                    }
                }
            }
        }
    }
}

class Bank {

    long[] balance;

    public Bank(long[] balance) {
        this.balance = balance;
    }

    public boolean transfer(int account1, int account2, long money) {
        if(account1 < 0 || account1 > balance.length ||
           account2 < 0 || account2 > balance.length || balance[account1 - 1] < money ) {
            return false;
        }
            balance[account1 - 1] -= money;
            balance[account2 - 1] += money;
            return true;
    }

    public boolean deposit(int account, long money) {
        if(account < 0 || account > balance.length ) {
            return false;
        }
        balance[account - 1] += money;
        return true;
    }

    public boolean withdraw(int account, long money) {
        if(account < 0 || account > balance.length || balance[account - 1] < money ) {
            return false;
        }

        balance[account - 1] -= money;
        return true;
    }

    public void show(int account){
        System.out.println("剩余存款为" + balance[account]);
    }
}

